<div style="height:30px;border-bottom:4px solid #DFDFDF;">
  <p class="pull-left" style="font-size:16px; line-height:30px;">
      <strong><?php echo $this->translate('在线手机模板安装'); ?></strong>
      <small><strong style="color: red;"><?php echo $this->translate('收费模板，请到官方服务平台进行购买，服务平台地址：'); ?><a href="http://shop.dbshop.net" target="_blank">shop.dbshop.net</a></strong></small>
  </p>
  <p class="pull-right">
      <a href="<?php echo $this->url('phonetemplate/default'); ?>" class="btn btn-small"><i class="icon-arrow-left"></i> <?php echo $this->translate('返回模板管理'); ?></a>&nbsp;
      <a href="<?php echo $this->myviewalias()->dbshopHelpUrl('admin_template'); ?>" target="_blank" class="btn btn-small btn-info"><i class="icon-info-sign icon-white"></i> <?php echo $this->translate('查看帮助说明'); ?></a>
  </p>
</div>
<div class="well well-small" style="margin-top:6px; background-color:#FFF;">
    <table width="100%">
        <tbody>
        <?php
        if(isset($this->online_template_list) and !empty($this->online_template_list)) {
        $b_num = count($this->online_template_list)-1;
        foreach($this->online_template_list as $b_key => $online_template_value) {
        $b_y_num = $b_key%4; if ($b_key == 0) echo '<tr>';
        if ($b_y_num==0 and $b_key!=0) echo '</tr><tr>';
        if ($b_num==$b_key) {
        ?>
            <td width="25%">
        	<div style="border: 1px solid #aaa;margin: 5px 8px 5px 8px;padding: 5px;">
        		<img src="<?php echo $this->update_url . $online_template_value['template_image']; ?>" style="width: 100%;"  />
            	<div class="caption">
                	<table width="100%">
                    	<tr bgcolor="#CCCCCC">
                            <td><h4>&nbsp;<?php echo $online_template_value['template_name']; ?>&nbsp;<font size="2">(<?php echo (isset($online_template_value['template_price']) and $online_template_value['template_price'] > 0) ? '￥'.$online_template_value['template_price'] : $this->translate('免费'); ?>)</font></h4></td>
                            <td align="right">
                                <?php
                                $install_state = false;
                                if(in_array($online_template_value['template_str'], $this->installed_template)) $install_state = true;
                                ?>
                                <span id="install_button_<?php echo $online_template_value['template_id']; ?>">
                                <a href="javascript:;" onclick="online_template_info(<?php echo $online_template_value['template_id']; ?>);" style="cursor:pointer;" class="btn btn-info btn-large"><?php echo $this->translate('简介'); ?></a>&nbsp;

                                    <a href="javascript:;" <?php if(!$install_state) echo 'onclick="start_install_template('.$online_template_value['template_id'].');"'; ?> class="btn btn-large <?php if($install_state) echo 'btn-success'; else echo 'btn-primary'; ?>" style="cursor:pointer;"><?php if($install_state) echo $this->translate('已安装'); else echo $this->translate('安装'); ?></a>&nbsp;
                                </span>
                            </td>
                        </tr>
                    </table>
                </div>
        	</div>
            </td>
            <?php $y_td_num = 4-$b_y_num-1;
            for($i=1;$i<=$y_td_num; $i++) {
                echo '<td width="25%"></td>';
            }
            ?>
            </tr>
        <?php } else { ?>
            <td width="25%">
        	<div style="border: 1px solid #aaa;margin: 5px 8px 5px 8px;padding: 5px;">
        		<img src="<?php echo $this->update_url . $online_template_value['template_image']; ?>" style="width: 100%;"  />
            	<div class="caption">
                	<table width="100%">
                    	<tr bgcolor="#CCCCCC">
                            <td><h4>&nbsp;<?php echo $online_template_value['template_name']; ?>&nbsp;<font size="2">(<?php echo (isset($online_template_value['template_price']) and $online_template_value['template_price'] > 0) ? '￥'.$online_template_value['template_price'] : $this->translate('免费'); ?>)</font></h4></td>
                            <td align="right">
                                <?php
                                $install_state = false;
                                if(in_array($online_template_value['template_str'], $this->installed_template)) $install_state = true;
                                ?>
                                <span id="install_button_<?php echo $online_template_value['template_id']; ?>">
                                <a href="javascript:;" onclick="online_template_info(<?php echo $online_template_value['template_id']; ?>);" style="cursor:pointer;" class="btn btn-info btn-large"><?php echo $this->translate('简介'); ?></a>&nbsp;

                                    <a href="javascript:;" <?php if(!$install_state) echo 'onclick="start_install_template('.$online_template_value['template_id'].');"'; ?> class="btn btn-large <?php if($install_state) echo 'btn-success'; else echo 'btn-primary'; ?>" style="cursor:pointer;"><?php if($install_state) echo $this->translate('已安装'); else echo $this->translate('安装'); ?></a>&nbsp;
                                </span>
                            </td>
                        </tr>
                    </table>
                </div>
        	</div>
            </td>
        <?php } } } else { ?>

                <?php if (isset($this->soap_state) and $this->soap_state!='') { ?>
                <?php if($this->soap_state=='false') {?>
                    <span class="label label-important"><h5><?php echo $this->translate('您的环境没有开启soap，不能使用该功能！'); ?></h5></span>
                <?php } elseif ($this->soap_state=='no_link') {?>
                    <span class="label label-important"><h5><?php echo $this->translate('无法连接更新服务器，不能使用该功能！'); ?></h5></span>
                <?php } ?>
        <?php } ?>
        <span class="label label-info"><h5><?php echo $this->translate('暂时没有新模板！'); ?></h5></span>
        <?php } ?>
        </tbody>
    </table>
</div>

<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

</div>

<script>
    function online_template_info(template_id) {
        $.post("<?php echo $this->url('phonetemplate/default',array('action'=>'templatePhoneInfo')); ?>",{template_id:template_id},
            function(data){
                if(data != 'false') {
                    $('#myModal').html(data);
                    $('#myModal').modal('show');
                } else {
                    alert('<?php echo $this->translate('没有介绍信息！'); ?>');
                }
            });
        return true;
    }
    function start_install_template(template_id) {
        var img_str = '<img src="<?php echo $this->basePath('public/admin/img/update_loading_black.gif'); ?>" border="0" /><strong><?php echo $this->translate('安装中……'); ?></strong>&nbsp;';
        $('#install_button_'+template_id).html(img_str);

        $.post("<?php echo $this->url('phonetemplate/default',array('action'=>'startInstallPhoneTemplate')); ?>",{template_id:template_id},
            function(data){
                if(data == 'true') {
                    alert('<?php echo $this->translate('模板安装成功！'); ?>');
                } else {
                    alert(data);
                    $('#install_button_'+template_id).html('<?php echo $this->translate('刷新页面，再次尝试安装！'); ?>');
                    return false;
                }
                window.location.href="<?php echo $this->url('phonetemplate/default', array('action'=>'installPhoneTemplate')); ?>";
            });
    }
</script>
